﻿
using JshRCSWebApi.Infrastructure.Domain.DTO.SysService;

public class MenuController : BaseController
{
    private readonly MenuService _menuService;

    public MenuController(MenuService menuService, IHttpContextAccessor httpContextAccessor)
        : base(httpContextAccessor)
    {
        _menuService = menuService;
    }
     
    /// <summary>
    /// 获取菜单列表(树形-用于列表展示)
    /// </summary>
    /// <param name="searchDTO"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResult> GetMenuList([FromBody] MenuSearchDTO searchDTO)
           => await Task.Run(async () => await _menuService.GetMenuList(searchDTO));

    /// <summary>
    /// 获取权限的ID和标题（树形-用于菜单权限分配）
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<ApiResult> GetMenuIDAndTitleList()
        => await Task.Run(async () => await _menuService.GetMenuIDAndTitleList());

    /// <summary>
    /// 新增菜单
    /// </summary>
    /// <param name="addDTO"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResult> AddMenu([FromBody] MenuAddDTO addDTO )
        => await Task.Run(async () => await _menuService.AddMenu(addDTO, Convert.ToInt32(GetUser("ID"))));

    /// <summary>
    /// 删除菜单
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    [HttpDelete]
    public async Task<ApiResult> DeleteMenu(int ID)
        => await Task.Run(async () => await _menuService.DeleteMenu(ID));

    /// <summary>
    /// 修改菜单
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResult> UpdateMenu([FromBody] MenuUpdateDTO updateDTO)
        => await Task.Run(async () => await _menuService.UpdateMenu(updateDTO, Convert.ToInt32(GetUser("ID"))));

    /// <summary>
    /// 菜单上移
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<ApiResult> MoveUpMenu(int ID)
        => await Task.Run(async () => await _menuService.MoveUpMenu(ID));

    /// <summary>
    /// 菜单下移
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<ApiResult> MoveDownMenu(int ID)
        => await Task.Run(async () => await _menuService.MoveDownMenu(ID));

    /// <summary>
    /// 获取父级菜单
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<ApiResult> GetParentsMenus()
        => await Task.Run(async () => await _menuService.GetParentsMenus());

    /// <summary>
    /// 根据ID获取菜单集合
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<ApiResult> GetMenuListByID(int ID)
        => await Task.Run(async () => await _menuService.GetMenuListByID(ID));

}
